#coding=utf-8
from database.db_handler import MysqlHander
import urllib.request
from bs4 import BeautifulSoup
import glob
import jieba
import re
import json

'''
属性枚举值入库
'''

class MarkteEntityDb:
    def __init__(self, file, entity_type):
        self.db = MysqlHander("config.ini")
        self.file = file
        self.entity_type = entity_type
    
    def write_db(self, d):
        b = d.strip().replace("\n", "").replace("\r", "")
        if len(b) == 0:
            return
        sql = "insert into market_entity_data (Fentity_type, Fentity_name, Fcreate_time, Fmodify_time) values "
        sql += "(" + str(self.entity_type) + ",'" + b + "', now(), now());"
        print(sql)
        try:
            self.db.execute_not_safe(sql)
        except Exception as e:
            pass
    
    def record_attr(self):
        with open(self.file, 'r', encoding='utf-8') as f:
            self.data = f.readlines()
        for b in self.data:
            self.write_db(b)

if __name__ == '__main__':
    #code = MarkteEntityDb('./src/diqu.txt', 200)
    #code = MarkteEntityDb('./src/dazongshangpin.txt', 300)
    #code = MarkteEntityDb('./src/huobi.txt', 400)
    code = MarkteEntityDb('./src/GDP80.txt', 500)
    code.record_attr()